$(function () {
  // 修改密码操作

  $('.reset').click(function () {
    // 获取input框的值
    let userPass = $('#old').val()
    let newPass = $('#password').val()
    let confirmPass = $('#confirm').val()

    // 发送ajax请求
    if (window.isLogin) {
      $.ajax({
        url: baseUrl + '/users/password',
        type: 'PUT',
        xhrFields: {
          withCredentials: true
        },
        data: {
          userPass,
          newPass,
          confirmPass
        },
        success(res) {
          console.log(res);
          window.location.href = 'login.html'

        },
        error(err) {
          console.log(err);
        }
      })
    }

    return false
  })



  //点击退出登录操作

  $('.logout').click(function () {

    if (window.isLogin) {
      $.ajax({
        url: baseUrl + '/logout',
        type: 'POST',
        success(res) {
          if (res.message === '退出成功') {

            window.sessionStorage.clear()
            window.location.href = 'login.html'

          }
        },
        error(err) {
          console.log(err);
        }
      })
    } else {
      window.location.href = 'login.html'
    }


  })



})